package com.passion.fs.controller;

import com.ramostear.captcha.HappyCaptcha;
import com.ramostear.captcha.support.CaptchaType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述：验证码生成控制器
 *
 * @author ZhuYin
 * @since 2025年01月07日
 */
@Slf4j
@Controller
public class CaptchaController {

    /**
     * 方法说明：生成图形验证码
     *
     * @param request   请求对象
     * @param response  响应对象
     * @author ZhuYin
     * @since 2025年01月07日
     */
    @RequestMapping("/assets/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) {
        HappyCaptcha.require(request, response)
                .type(CaptchaType.WORD_UPPER)
                .length(4)
                .build().finish();
        // String captcha = (String) request.getSession().getAttribute("happy-captcha");
        // log.info("生成的验证码为：{}", captcha);
    }

}
